<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../../js/vue.js"></script>
    <script src="../../js/vue-router.js"></script>
</head>

<body>



    <div id="app">
        <router-link to="/user/1">User1</router-link>
        <router-link to="/user/2">User2</router-link>
        <router-link to="/user/3">User3</router-link>
        <!-- to 属性是动态属性绑定，所以要在前面加上个冒号 -->
        <router-link :to="{ name: 'user', params: { id: 22 }}">User4</router-link>
        <router-view></router-view>
    </div>

    <script>
        const User = {
            props: ['id', 'name', 'age'],
            template: '<h1>user{{ id }}组件信息--name:{{ name }}---age:{{ age }}</h1>'
        }

        var router = new VueRouter({
            routes: [
                {
                    name: 'user',
                    path: '/user/:id',
                    component: User,
                    props: function (route) {
                        return {
                            age: 128,
                            name: 'lisi',
                            id: route.params.id
                        }
                    }
                }
            ]
        })

        var vm = new Vue({
            el: '#app',
            router: router
        })
    </script>
</body>

</html>